
// const Home = () => import("@/pages/Home")
// const Login = () => import("@/pages/Login")
// const Register = () => import("@/pages/Register")
// const Search = () => import("@/pages/Search")

// 路由懒加载推荐写法 可以直接路由懒加载方法写在路由组件中
export default [
    {
        // 默认入口路由
        path: "/",
        redirect: "/home",
    },
    {
        path: "/home",
        name: "home",
        component: () => import("@/pages/Home"),
    },
    {
        path: "/login",
        name: "login",
        component: () => import("@/pages/Login"),
        // 配置路由元信息控制底部组件按需加载
        meta: {
            isHidden: true,
        }
    },
    {
        path: "/register",
        name: "register",
        component: () => import("@/pages/Register"),
        meta: {
            isHidden: true,
        }
    },
    {
        path: "/search/:keyword?",
        name: "search",
        component: () => import("@/pages/Search"),
    },
    {
        path: "/detail/:skuId",
        name: "detail",
        component: () => import("@/pages/Detail"),
    },
    {
        path: "/addCartSuccess",
        name: "addCartSuccess",
        component: () => import("@/pages/AddCartSuccess"),
        // 路由独享守卫
        beforeEnter: (to, from, next) => {
            // 判断如果来电路由地址是商品详情页，则放行，否则导航回到购物车页
            if (from.name === "detail") {
                next();
            } else {
                next("/detail")
            }
        }
    },
    {
        path: "/shopCart",
        name: "shopCart",
        component: () => import("@/pages/ShopCart"),
    },
    {
        path: "/trade",
        name: "trade",
        component: () => import("@/pages/Trade"),
        // 路由独享守卫
        beforeEnter: (to, from, next) => {
            // 判断如果来电路由地址是购物车页，则放行，否则导航回到购物车页
            if (from.name === "shopCart") {
                next();
            } else {
                next("/shopCart")
            }
        }
    },
    {
        path: "/pay",
        name: "pay",
        component: () => import("@/pages/Pay"),
        // 路由独享守卫
        beforeEnter: (to, from, next) => {
            // 判断如果来电路由地址是trade页，则放行，否则导航回到购物车页
            if (from.name === "trade") {
                next();
            } else {
                next("/shopCart")
            }
        }
    },
    {
        path: "/paySuccess",
        name: "paySuccess",
        component: () => import("@/pages/PaySuccess"),
        // 路由独享守卫
        beforeEnter: (to, from, next) => {
            // 判断如果来电路由地址是pay支付页，则放行，否则导航回到购物车页
            if (from.name === "pay") {
                next();
            } else {
                next("/shopCart")
            }
        }
    },
    {
        path: "/center",
        // name: "center",
        redirect: "/center/myOrder",
        component: () => import("@/pages/Center"),
        children: [
            {
                path: "myOrder",
                name: "myOrder",
                component: () => import("@/pages/Center/components/MyOrder")
            },
            {
                path: "teamOrder",
                name: "teamOrder",
                component: () => import("@/pages/Center/components/TeamOrder")
            }
        ]
    },
];